//
//  ViewController.swift
//  ShadowRoundedCornerDemo2
//
//  Created by 李煜 on 2024/5/15.
//

import UIKit

class ViewController: UIViewController {
    ///v.layer.masksToBounds是裁剪v.sublayer与v.bounds一致
    ///所以v.layer.masksToBounds = false
    ///
    /// 1.视图v无子视图:其实设置v(圆角+阴影)即可v.layer.masksToBounds=yes|no都不影响
    /// 2.视图v有子视图:父视图/子视图均设置圆角+其一设置阴影,并且v.layer.masksToBounds = false,如果true会裁剪阴影,导致显示不了阴影

    let tip: UIView = {
        //父视图
        let v = UIView(frame: .init(x: 20, y: 50, width: 100, height: 100))
        v.backgroundColor = .blue
        v.layer.cornerRadius = 6
                
        //子视图
        let a = UIView(frame: v.bounds)
        v.addSubview(a)
        //a圆角
        a.layer.cornerRadius = 6
        a.backgroundColor = .red
        
        v.layer.shadowColor = UIColor.black.cgColor
        v.layer.shadowOffset = CGSize(width: 12, height: 12)
        v.layer.shadowOpacity = 0.7
        v.layer.shadowRadius = 2
        v.layer.shadowPath = UIBezierPath(roundedRect: v.bounds, cornerRadius: v.layer.cornerRadius).cgPath
        
        
        
        
        return v
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .init(white: 0.5, alpha: 0.5)
        view.addSubview(tip)
    }


}

